package masterjava.common.shared.state;

import org.jetbrains.annotations.Nullable;

public class StateException extends RuntimeException {

    private final State state;

    public StateException(String message) {
        this(message, StateType.ERROR);
    }

    public StateException(String message, Exception e) {
        this(message + " (" + e.getMessage() + ")", StateType.ERROR, e);
    }

    public StateException(String message, StateType type) {
        this(message, StateType.ERROR, null);
    }

    public StateException(String message, StateType type, @Nullable Exception e) {
        super(message);
        this.state = new State();
        state.setState(type, message, e);
    }

    public StateException(State state) {
        super(state.getMessage());
        this.state = state;
    }

    public State getState() {
        return state;
    }
}